//
//  MainViewController.swift
//  XLWB
//
//  Created by 郭亮 on 16/3/11.
//  Copyright © 2016年 gl. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    //MARK:-懒加载属性
    private lazy var plusBtn: UIButton = UIButton(imageName: "tabbar_compose_icon_add", backImageName: "tabbar_compose_button")

    //MARK:-系统回调方法
    override func viewDidLoad() {
        super.viewDidLoad()
        setupPlusBtn()
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        //设置中间item不能点击
        let index = tabBar.items!.count / 2
        tabBar.items![index].enabled = false
    }
}

//MARK:-处理UI
extension MainViewController {
    /// 设置发布按钮
    private func setupPlusBtn() {
        plusBtn.center = CGPoint(x: tabBar.frame.width * 0.5, y: tabBar.frame.height * 0.5)
        tabBar.addSubview(plusBtn)
        //监听事件点击
        plusBtn.addTarget(self, action: "plusBtnClick", forControlEvents: .TouchUpInside)
    }
    
    @objc private func plusBtnClick() {
        //弹出发布控制器
        let composeVc = ComposeViewController()
        let navVc = UINavigationController(rootViewController: composeVc)
        presentViewController(navVc, animated: true, completion: nil)
    }
}
